package com.skirmisher.inspection.rectify.controller;

import com.skirmisher.inspection.common.entity.InsUser;
import com.skirmisher.inspection.common.entity.InsUserEntity;
import com.skirmisher.inspection.common.utils.PageUtils;
import com.skirmisher.inspection.daily.entity.InsDailyJob;
import com.skirmisher.inspection.inspection.testController.ResponseModel;
import com.skirmisher.inspection.rectify.entity.InsJobRectify;
import com.skirmisher.inspection.rectify.entity.InsJobRectifyPageQuery;
import com.skirmisher.inspection.rectify.service.InsJobRectifyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName InsJobRectifyController
 * @Description TODO
 * @Author hanwangxin
 * @Date 2020/12/14 下午9:21
 * @Version 1.0
 */
@Api(tags = "巡查整改接口")
@RestController
@RequestMapping("/jobRectify")
public class InsJobRectifyController {

    @Autowired
    private InsJobRectifyService insJobRectifyService;

    @ApiOperation(value = "整改任务页面加载")
    @GetMapping(value = "/rectifyPageQuery")
    public ResponseModel rectifyPageQuery(InsJobRectifyPageQuery query){

        ResponseModel responseModel = new ResponseModel();
        //参数校验
        Integer startRow = PageUtils.getStartRow(query.getPage(), query.getRows());
        if (startRow == null || startRow < 0){
            responseModel.setCode(201);
            responseModel.setMessage("分页参数有误");
            return  responseModel;
        }
        query.setStartRows(startRow);
        insJobRectifyService.rectifyPageQuery(query);
        responseModel.setDataDataGrid(query.getDateList(), query.getCount());


        return responseModel;

    }

    /**
     * @Author hanwangxin
     * @Description //TODO  * @Date 下午10:03 2020/12/14
     * @Param [rectifyId]
     * @return com.skirmisher.inspection.inspection.testController.ResponseModel
     **/
    @ApiOperation(value = "整改任务详情数据")
    @GetMapping(value = "/rectifyDetail")
    @ApiImplicitParam(name = "rectifyId",value = "整改任务id",required = true)
    public ResponseModel rectifyDetail(String rectifyId){

        ResponseModel responseModel = new ResponseModel();
        if (StringUtils.isEmpty(rectifyId)){
            responseModel.setCode(201);
            responseModel.setMessage("无任务id");
            return responseModel;
        }
        InsJobRectify rectify = insJobRectifyService.rectifyDetail(rectifyId);
        responseModel.setData(rectify);
        return  responseModel;
    }

    /**
     * @Author hanwangxin
     * @Description //TODO  * @Date 下午8:16 2020/12/15
     * @Param [user]
     * @return com.skirmisher.inspection.inspection.testController.ResponseModel
     **/
    @ApiOperation(value = "审核整改任务")
    @PostMapping(value = "/checkRectifyDetail")
    public ResponseModel checkRectifyDetail(@RequestBody @Validated InsUserEntity user){

        ResponseModel responseModel = new ResponseModel();
        insJobRectifyService.checkRectifyDetail(user);

        return  responseModel;

    }

    /**
     * @Author hanwangxin
     * @Description //TODO  * @Date 下午8:38 2020/12/15
     * @Param [user]
     * @return com.skirmisher.inspection.inspection.testController.ResponseModel
     **/
    @ApiOperation(value = "整改任务派工")
    @PostMapping(value = "/sendInsRectifyDetail")
    public ResponseModel sendInsRectifyDetail(@RequestBody @Validated InsUserEntity user){
        ResponseModel responseModel = new ResponseModel();
        insJobRectifyService.sendInsRectifyDetail(user);

        return  responseModel;
    }




}
